/**
 * Created by shitao on 15/11/2.
 */
(function () {
    angular.module('my-tabs.controllers')
        .controller('storeCtrl', storeCtrl);
    storeCtrl.$inject = ['$scope', 'exploreService', '$stateParams', '$ionicHistory', '$ionicScrollDelegate'];

    function storeCtrl($scope, exploreService, $stateParams, $ionicHistory, $ionicScrollDelegate) {
        console.log('storeCtrl');
        var vm = this,
            storeId = $stateParams.storeId;
        vm.store = exploreService.getStore(storeId);

        $scope.$on('$ionicView.beforeEnter', function () {
            var navBar = angular.element(document.querySelectorAll('ion-header-bar'));
            navBar.css('opacity', 0);
        });
        $scope.$on('$ionicView.beforeLeave', function () {
            var navBar = angular.element(document.querySelectorAll('ion-header-bar'));
            navBar.css('opacity', 1);
        });

        vm.onContentScroll = function () {
            var scrollDelegate = $ionicScrollDelegate.$getByHandle('contentScroll');
            var scrollView = scrollDelegate.getScrollView();
            var innerBar = angular.element(document.querySelector('.inner-bar'));
            var navBar = angular.element(document.querySelectorAll('ion-header-bar'));
            if (scrollView.__scrollTop > 0) {
                innerBar.addClass('hide');
                navBar.css('opacity', Math.min(scrollView.__scrollTop / 150, 1));
            }else{
                innerBar.removeClass('hide');
                navBar.css('opacity', 0);
            }
        };
        vm.back = function(){
            $ionicHistory.goBack();
        };
    }
})();
